﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace Misuzilla.Crigate.Handler
{
    [Serializable]
    public class HandlerTypeInfo
    {
        public String Assembly { get; set; }
        public String CodeBase { get; set; }
        public String Type { get; set; }
        public Boolean IsAutoActivate { get; set; }
        public Boolean IsRequireParentDomain { get; set; }
        public Boolean IsRequireIsolatedDomain { get; set; }
        public String SharedAppDomainName { get; set; }
        public ActivateContexts ActivateContext { get; set; }
        
        public IHandler CreateInstance()
        {
            Assembly asm = System.Reflection.Assembly.LoadFrom(CodeBase);
            Type t = asm.GetType(Type);
            return Activator.CreateInstance(t) as IHandler;
        }

        public override string ToString()
        {
            return "HandlerTypeInfo: " + Type;
        }
    }
    

    public class HandlerTypeInfoComparer : IComparer<HandlerTypeInfo>
    {
        #region IComparer<HandlerTypeInfo> メンバ

        public int Compare(HandlerTypeInfo x, HandlerTypeInfo y)
        {
            return ((x.Assembly                == y.Assembly) &&
                    (x.CodeBase                == y.CodeBase) &&
                    (x.IsAutoActivate          == y.IsAutoActivate) &&
                    (x.IsRequireIsolatedDomain == y.IsRequireIsolatedDomain) &&
                    (x.IsRequireParentDomain   == y.IsRequireParentDomain) &&
                    (x.SharedAppDomainName     == y.SharedAppDomainName) &&
                    (x.ActivateContext         == y.ActivateContext) &&
                    (x.Type == y.Type))
                       ? 0
                       : 1;
        }

        #endregion
    }
}
